package com.wxl.common.wiget

import android.content.Context
import android.text.InputType
import android.util.AttributeSet
import android.widget.AdapterView
import android.widget.ArrayAdapter
import com.wxl.common.R
import com.wxl.common.util.DPUtil

class SpinnerDropDownAppEditorText : SkinKeyEventEditorText {

    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    )

    fun show(data:List<String>,onItemClick:AdapterView.OnItemClickListener){
        setInputType(InputType.TYPE_NULL)
        setOnItemClickListener(onItemClick)
        setOnDismissListener {
            setFocusable(false)
        }
        setAdapter(
            ArrayAdapter<String>(
                context,
                R.layout.item_spinner,
                R.id.tv_content,
                data.toTypedArray()
            ))
        setOnClickListener {
            setFocusableInTouchMode(true)
            requestFocusFromTouch()
            setDropDownWidth(DPUtil.dip2px(200))
            showDropDown()
        }
    }


    fun show(data:List<String>,width:Int,onItemClick:AdapterView.OnItemClickListener){
        setInputType(InputType.TYPE_NULL)
        setOnItemClickListener(onItemClick)
        setOnDismissListener {
            setFocusable(false)
        }
        setAdapter(
            ArrayAdapter<String>(
                context,
                R.layout.item_spinner,
                R.id.tv_content,
                data.toTypedArray()
            ))
        setOnClickListener {
            setFocusableInTouchMode(true)
            requestFocusFromTouch()
            setDropDownWidth(width)
            showDropDown()
        }
    }
}